package com.sskj.lib.util;

import android.app.Activity;
import android.text.TextUtils;

import com.alibaba.android.arouter.launcher.ARouter;
import com.sskj.common.base.App;
import com.sskj.common.util.ToastUtil;
import com.sskj.lib.R;
import com.sskj.lib.RConfig;
import com.sskj.lib.bean.UserData;

public class AppCircleCheckUtil {


    /**
     * 检测是否登录，没有登录直接跳转登录界面
     *
     * @param activity
     * @param userData
     * @return
     */
    public static boolean checkLogin(Activity activity, UserData userData) {
        if (userData == null) {
            ARouter.getInstance().build(RConfig.LOGIN_LOGIN).navigation();
            activity.overridePendingTransition(R.anim.lib_anim_in, R.anim.lib_anim_out);
            return false;
        }
        return true;
    }

    /**
     * 验证手机号
     *
     * @param userData
     * @return
     */
    public static boolean checkTel(Activity activity, UserData userData) {
        if (TextUtils.isEmpty(userData.getPhone())) {
            ToastUtil.showShort(App.INSTANCE.getString(R.string.lib_appCircleCheckUtil1));
            return false;
        }
        return true;
    }

    /**
     * 验证实名认证
     *
     * @param userData
     * @return
     */
    public static boolean checkAuth(Activity activity, UserData userData) {
        switch (userData.getAuthentication()) {
            case 0://未实名认证
            case 3://实名认证已拒绝
                TipUtil.getSureCancelTip(activity, App.INSTANCE.getString(R.string.lib_appCircleCheckUtil2), App.INSTANCE.getString(R.string.lib_appCircleCheckUtil3), App.INSTANCE.getString(R.string.lib_appCircleCheckUtil4), () -> {
                    ARouter.getInstance().build(RConfig.MINE_IDENTITY_VERIFY).navigation();
                });
                return false;
            case 1://实名认证审核中
                ToastUtil.showShort(App.INSTANCE.getString(R.string.lib_appCircleCheckUtil5));
                return false;
        }

        //2 认证通过
        return true;
    }

    /**
     * 验证高级实名认证
     *
     * @param userData
     * @return
     */
    public static boolean checkHighAuth(Activity activity, UserData userData) {
        if (userData.getAuthentication() != 2) {
            TipUtil.getSureCancelTip(activity, App.INSTANCE.getString(R.string.lib_appCircleCheckUtil2), App.INSTANCE.getString(R.string.lib_appCircleCheckUtil6), App.INSTANCE.getString(R.string.lib_appCircleCheckUtil4), () -> {
                ARouter.getInstance().build(RConfig.MINE_SECURITY_VERIFYHOME).navigation();
            });
            return false;
        }
        return true;
    }


    /**
     * 验证资金密码
     *
     * @param userData
     * @return
     */
    public static boolean checkTradePwd(Activity activity, UserData userData) {
        if (userData.getConfig().getPayment_password_set() != 0) {
            return true;
        } else {
            TipUtil.getSureCancelTip(activity, App.INSTANCE.getString(R.string.lib_appCircleCheckUtil7), App.INSTANCE.getString(R.string.lib_appCircleCheckUtil8), App.INSTANCE.getString(R.string.lib_appCircleCheckUtil4), () -> {
                ARouter.getInstance().build(RConfig.MINE_SECURITY_CENTER).navigation();
//                ARouter.getInstance().build(RConfig.MINE_SET_PAY_PWD)
//                        .withString("mobile", userData.getPhone())
//                        .withInt("type", userData.getConfig().getPayment_password_set() == 0 ? 1 : 2).navigation();

            });
            return false;
        }
    }

    /**
     * 验证支付方式
     *
     * @param userData
     * @return
     */
    public static boolean checkPayType(Activity activity, UserData userData) {

//        if (TextUtils.isEmpty(userData.getPayment_type())) {
//            TipUtil.getSureCancelTip(activity, App.INSTANCE.getString(R.string.lib_appCircleCheckUtil2), App.INSTANCE.getString(R.string.lib_appCircleCheckUtil9), App.INSTANCE.getString(R.string.lib_appCircleCheckUtil10), () -> {
//                ARouter.getInstance().build(RConfig.MINE_PAYMENT).navigation();
//            });
//            return false;
//        }
        return true;
    }


    /**
     * 验证商家
     *
     * @param userData
     * @return
     */
    public static boolean checkShop(Activity activity, UserData userData) {
        if (userData.getIs_shop() == 0) {  // 不是商家
            TipUtil.getSureCancelTip(activity, App.INSTANCE.getString(R.string.lib_appCircleCheckUtil11), App.INSTANCE.getString(R.string.lib_appCircleCheckUtil12), App.INSTANCE.getString(R.string.lib_appCircleCheckUtil4), () -> {
                ARouter.getInstance().build(RConfig.MINE_SELLER_APPLY).navigation();
            }).show();
            return false;
        }
        if (userData.getIs_shop() == 2) {
            ToastUtil.showShort(App.INSTANCE.getString(R.string.lib_appCircleCheckUtil13));
            return false;
        }
        if (userData.getIs_shop() == 3) {
            ToastUtil.showShort(App.INSTANCE.getString(R.string.lib_appCircleCheckUtil14));
            return false;
        }


        return true;
    }


    /**
     * 验证谷歌短信开关，至少开启一个
     *
     * @param activity
     * @param userData
     * @return
     */
    public static boolean checkGoogleSms(Activity activity, UserData userData) {
        if (userData.getConfig().getGoogle_verify() == 0 && userData.getConfig().getSms_verify() == 0) {
            TipUtil.getSureCancelTip(activity, App.INSTANCE.getString(R.string.lib_appCircleCheckUtil11), App.INSTANCE.getString(R.string.lib_appCircleCheckUtil15), () -> {

            });
            return false;
        }
        return true;
    }
}
